from django.shortcuts import render
from rest_framework.views import APIView
# Create your views here.
from  rest_framework.response import Response
from .models import *
class UsernameCountView(APIView):
    def get(self,request,username):
        if not username:
            return Response({'errmsg':'缺少用户名','code':400})

        try:
            num =User.objects.filter(username=username).count()
            return Response({'errmsg':'ok','count':num,'code':400})

        except User.DoesNotExist:
            return Response({'errmsg':'ok','count':num,'code':0})
class MobileCountView(APIView):
    def get(self,request,mobile):
        if not mobile:
            return Response({'errmsg':'缺少手机号','code':400})

        try:
            num =User.objects.filter(mobile=mobile).count()
            return Response({'errmsg':'ok','count':num,'code':400})

        except User.DoesNotExist:
            return Response({'errmsg':'ok','count':num,'code':0})
